#include "TexturePNGReader.h"

#include <string>
#include <boost/gil/gil_all.hpp>
#include <boost/gil/extension/io/png_io.hpp>
#include <boost/gil/extension/dynamic_image/any_image.hpp>
#include <boost/mpl/vector.hpp>

using namespace boost::gil;
using namespace boost;
using namespace std;

void TexturePNGReader::Read(const std::string & iFileName, unsigned char *& oImage, unsigned int & oWidth, unsigned int & oHeight)
{
   bgr8_image_t img;
   png_read_image(iFileName.c_str(), img);
   bgr8_view_t v = view( img ); 
   
   oWidth  = v.width();
   oHeight = v.height();
   
   unsigned char * imgTmp = reinterpret_cast<unsigned char*>( interleaved_view_get_raw_data(v) );
   oImage = new unsigned char[oWidth * oHeight * 3];

   memcpy(oImage, imgTmp, oWidth * oHeight * 3 * sizeof(unsigned char));

}
